<script lang="ts" setup>
import { useVModel } from '@vueuse/core'
import { ref, type Component } from 'vue'

const props = defineProps<{
  visible: boolean
  comp?: Component
}>()

const emits = defineEmits<{
  (e: 'update:visible', bool: boolean): void
}>()

const show_drawer = useVModel(props, 'visible', emits)

const component_ref = ref()

defineExpose({
  component_ref
})
</script>

<template>
  <a-drawer
    v-bind="$attrs"
    v-model:visible="show_drawer"
    :title="component_ref?.title"
    :width="component_ref?.width ?? '960px'"
    :footer="component_ref?.footer ? true : false"
    :unmount-on-close="true"
    @cancel="show_drawer = false"
  >
    <Component
      :is="props.comp"
      v-if="props.comp"
      ref="component_ref"
      v-bind="$attrs"
      @close="show_drawer = false"
    />

    <template #footer>
      <component :is="component_ref?.footer" />
    </template>
  </a-drawer>
</template>

<style scoped lang="less"></style>
